<!--renshuai-->
<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="" prop="pdrName">
        <el-input
            v-model="queryParams.workerName"
            placeholder="师傅姓名"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="transactionId">
        <el-input
            v-model="queryParams.pkId"
            placeholder="工单编号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="" prop="settlemStatus">
        <el-select v-model="queryParams.settlemStatus" placeholder="结算状态" clearable>
          <el-option  v-for="(item,index) in settlemStatusList" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="" prop="workStatus">
        <el-select v-model="queryParams.workStatus" placeholder="工单状态" clearable>
          <el-option  v-for="(item,index) in workStatusList" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="dataList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="50px" align="center">
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column label="工单编号" align="center" prop="pkId"/>
      <el-table-column label="厂商名称" align="center" prop="producerName" :show-overflow-tooltip="true"/>
      <el-table-column label="工单价格" align="center" prop="workPrice" :show-overflow-tooltip="true"/>
      <el-table-column label="加急费用" align="center" prop="urgentPrice" :show-overflow-tooltip="true"/>
      <el-table-column label="师傅姓名" align="center" prop="workerName" :show-overflow-tooltip="true"/>
      <el-table-column label="师傅报酬" align="center" prop="workFee" :show-overflow-tooltip="true"/>
      <el-table-column label="师傅加急" align="center" prop="urgentFee" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.urgentStatus==1">{{scope.row.urgentFee}}</span>
        </template>
      </el-table-column>
      <el-table-column label="工单状态" align="center" prop="workStatus" width="90">
        <template slot-scope="scope">
          <dict-tag :options="workStatusList" :value="scope.row.workStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="结算结果" align="center" prop="settlemStatus" width="90">
        <template slot-scope="scope">
          <dict-tag :options="settlemStatusList" :value="scope.row.settlemStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime"  width="95">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button v-if="scope.row.settlemStatus=='0'"
              type="text"
              size="small"
              @click="handleSettlem(scope.row)"
              v-hasPermi="['fin:worker:settlemlist:settlem']">结算</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body center :before-close="handleClose">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="工单编号" prop="pkId">
              <span>{{form.order.pkId}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="厂商名称" prop="producerName">
              <span>{{form.order.producerName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工单价格" prop="workPrice">
              <span>{{form.order.workPrice}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="师傅报酬" prop="workFee">
              <span>{{form.order.workFee}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工单加急费" prop="urgentPrice">
              <span v-if="form.order.urgentStatus==1">{{form.order.urgentPrice}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="师傅加急报酬" prop="urgentFee">
              <span v-if="form.order.urgentStatus==1">{{form.order.urgentFee}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="师傅姓名" prop="workerName">
              <span>{{form.order.workerName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="处理人" prop="operUserName">
              <span>{{form.flow.operUserName}} / {{form.flow.operRealName}}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="备注" prop="details">
              <el-input v-model="form.flow.details"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSubmitForm">结 算</el-button>
        <el-button @click="handleClose">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {getWorkerOrdSettlem, listWorkerOrdSettlem, workerSettlem} from "@/api/fin/wkOrdSettlem";
import {dataSettlemStatusList, dataWorkStatusList} from "@/api/data/data";

export default {
  name: "WorkerOrderSettlemList",
  data() {
    return {
      settlemStatusList:dataSettlemStatusList,
      workStatusList:dataWorkStatusList,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      dataList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //是否打开编辑
      openIsEdit:false,
      // 查询参数
      queryParams: {
        workerName: undefined,
        pkId:undefined,
        settlemStatus: undefined,
        workStatus:"4",
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {
        order:{},
        flow:{}
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      listWorkerOrdSettlem(this.queryParams).then(response => {
        this.dataList = response.data;
        this.total = Number(response.total);
        this.loading = false;
      });
    },

    // 表单重置
    reset() {
      this.form = {
        order:{},
        flow:{}
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },


    handleSettlem(row){
      let orderId=row.pkId;
      getWorkerOrdSettlem(orderId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "结算";
      });
    },
    // 取消按钮
    handleClose() {
      this.open = false;
      this.reset();
    },

    onSubmitForm(){
      workerSettlem(this.form).then(response => {
        this.$modal.msgSuccess("保存成功");
        this.open = false;
        this.getList();
      });
    },

  }
};
</script>
<style lang="scss" scoped>
</style>